package be.jaisy.osgi.console.service.api.to;

import java.io.Serializable;

public class OsgiServiceTo implements Serializable {

	private static final long serialVersionUID = 4052013274459735625L;

	private Long id;

	private String[] interfaceClassNames;
	
	private Integer ranking;

	private String vendor;

	private String description;

	private Long registeredBundleId;

	private Long[] usedByBundleIds;

	public OsgiServiceTo() {
		super();
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String[] getInterfaceClassNames() {
		return interfaceClassNames;
	}

	public void setInterfaceClassNames(String[] interfaceClassNames) {
		this.interfaceClassNames = interfaceClassNames;
	}

	public Integer getRanking() {
		return ranking;
	}

	public void setRanking(Integer ranking) {
		this.ranking = ranking;
	}

	public Long getRegisteredBundleId() {
		return registeredBundleId;
	}

	public void setRegisteredBundleId(Long registeredBundleId) {
		this.registeredBundleId = registeredBundleId;
	}

	public String getVendor() {
		return vendor;
	}

	public void setVendor(String vendor) {
		this.vendor = vendor;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String name) {
		this.description = name;
	}

	public Long getRegisteredBundleid() {
		return registeredBundleId;
	}

	public void setRegisteredBundleid(Long registeredBundleid) {
		this.registeredBundleId = registeredBundleid;
	}

	public Long[] getUsedByBundleIds() {
		return usedByBundleIds;
	}

	public void setUsedByBundleIds(Long[] usedByBundleIds) {
		this.usedByBundleIds = usedByBundleIds;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer(OsgiServiceTo.class + " :");
		sb.append("[id=" + id + "]");
		sb.append("[interfaces=");
		if (interfaceClassNames != null) {
			for (int i = 0; i < interfaceClassNames.length; i++) {
				if (i < interfaceClassNames.length-1)
					sb.append(interfaceClassNames[i] + ",");
				else
					sb.append(interfaceClassNames[i]);
			}
		}
		sb.append("]");		
		sb.append("[ranking=" + ranking + "]");
		sb.append("[vendor=" + vendor + "]");
		sb.append("[description=" + description + "]");
		sb.append("[registeredBundleId=" + registeredBundleId + "]");
		sb.append("[usedByBundleIds=");
		if (usedByBundleIds != null) {
			for (int i = 0; i < usedByBundleIds.length; i++) {
				if (i < usedByBundleIds.length-1)
					sb.append(usedByBundleIds[i] + ",");
				else
					sb.append(usedByBundleIds[i]);
			}
		}
		sb.append("]");

		return sb.toString();
	}

	public int hashCode() {
		final int PRIME = 31;
		int result = 1;
		result = PRIME * result + ((description == null) ? 0 : description.hashCode());
		result = PRIME * result + ((id == null) ? 0 : id.hashCode());
		result = PRIME * result + ((interfaceClassNames == null) ? 0 : interfaceClassNames.hashCode());
		result = PRIME * result + ((ranking == null) ? 0 : ranking.hashCode());
		result = PRIME * result + ((registeredBundleId == null) ? 0 : registeredBundleId.hashCode());
		result = PRIME * result + ((usedByBundleIds == null) ? 0 : usedByBundleIds.hashCode());
		result = PRIME * result + ((vendor == null) ? 0 : vendor.hashCode());
		return result;
	}

	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
// Comment for GWT
//		if (getClass() != obj.getClass())
//			return false;
		final OsgiServiceTo other = (OsgiServiceTo) obj;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		if (interfaceClassNames == null) {
			if (other.interfaceClassNames != null)
				return false;
		} else if (!interfaceClassNames.equals(other.interfaceClassNames))
			return false;
		if (ranking == null) {
			if (other.ranking != null)
				return false;
		} else if (!ranking.equals(other.ranking))
			return false;
		if (registeredBundleId == null) {
			if (other.registeredBundleId != null)
				return false;
		} else if (!registeredBundleId.equals(other.registeredBundleId))
			return false;
		if (usedByBundleIds == null) {
			if (other.usedByBundleIds != null)
				return false;
		} else if (!usedByBundleIds.equals(other.usedByBundleIds))
			return false;
		if (vendor == null) {
			if (other.vendor != null)
				return false;
		} else if (!vendor.equals(other.vendor))
			return false;
		return true;
	}

	

}
